﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;

namespace PCSWpfData
{
    class CombinedDbContext : DbContext
    {
        public CombinedDbContext() : base()
        {
            //Database.SetInitializer<SchoolDBContext>(new CreateDatabaseIfNotExists<SchoolDBContext>());

            //Database.SetInitializer<SchoolDBContext>(new DropCreateDatabaseIfModelChanges<SchoolDBContext>());
            //Database.SetInitializer<CombinedDbContext>(new DropCreateDatabaseAlways<CombinedDbContext>());
            //Database.SetInitializer<SchoolDBContext>(new SchoolDBInitializer());
            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<CombinedDbContext>());

            Database.SetInitializer<CombinedDbContext>(new CombinedDBInitializer());
            


        }
        public DbSet<Instrument> Instruments { get; set; }
        public DbSet<PriceSeries> PriceSeries { get; set; }
        public DbSet<Price> Price { get; set; }
        public DbSet<Dividend> Dividend { get; set; }
        public DbSet<Statictics> Statistics { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            modelBuilder.Entity<Instrument>().HasMany<PriceSeries>(s => s.PriceSeriesList)
            .WithRequired(s => s.Instrument).HasForeignKey(s => s.InstrumentId);
            modelBuilder.Properties<DateTime>()
            .Configure(c => c.HasColumnType("datetime2"));
            base.OnModelCreating(modelBuilder);
        }
    }
}
